package com.yyh.xiancheng2;

public class Test3 {
    public static void main(String[] args) {
        //创建线程任务对象
        Runnable r = new MyTask1();
        //创建线程对象
        Thread t1 = new Thread(r, "线程1");
        //启动线程
        t1.start();
        //主程序等待t1线程执行完毕之后在执行
        try {
            t1.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //主程序任务执行
        for (int i = 1; i <= 10; i++){
            System.out.println(Thread.currentThread().getName() + "：" + i);
        }
    }
}
class  MyTask1 implements Runnable{
    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            System.out.println(Thread.currentThread().getName() + "：" + i);
        }
    }
}
